package com.example.rockapollo.listener;

import com.ctrip.framework.apollo.ConfigChangeListener;
import com.ctrip.framework.apollo.model.ConfigChange;
import com.ctrip.framework.apollo.model.ConfigChangeEvent;
import com.ctrip.framework.apollo.spring.annotation.ApolloConfigChangeListener;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class ApolloChangeListenerImpl implements ConfigChangeListener {

  /**
   * .监听Apollo 配置变化
   * @ApolloConfigChangeListener 监听指定namespace的配置
   * @param configChangeEvent
   */
  @Override
  @ApolloConfigChangeListener("notice")
  public void onChange(ConfigChangeEvent configChangeEvent) {
    for (String changedKey : configChangeEvent.changedKeys()) {
      ConfigChange change = configChangeEvent.getChange(changedKey);
      log.warn("found change - key:{},oldValue:{},newValue:{},changeType:{}",
          change.getPropertyName(), change.getOldValue(), change.getNewValue(),change.getChangeType());
    }
  }
}
